
FROM docker.domys.cc/python:3.12-slim-bullseye


ARG APT_MIRROR=https://mirrors.aliyun.com
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=core-apt \
    --mount=type=cache,target=/var/lib/apt,sharing=locked,id=core-apt \
    sed -i "s@http://.*.debian.org@${APT_MIRROR}@g" /etc/apt/sources.list \
    && rm -f /etc/apt/apt.conf.d/docker-clean \
    && apt-get update \
    && apt-get -y install --no-install-recommends pkg-config \
                                                  gcc \
                                                  cron \
                                                  tzdata


# 设置时区为上海（例如Asia/Shanghai）
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone


# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1


# 创建工作目录
WORKDIR /app


# 创建并编辑cron任务文件
COPY crontab.txt /etc/cron.d/wxmp
RUN chmod 0644 /etc/cron.d/wxmp && crontab /etc/cron.d/wxmp && touch /var/log/cron.log


# 安装依赖
COPY requirements.txt /app/
RUN pip install --upgrade pip -i https://pypi.doubanio.com/simple && pip install -r requirements.txt -i https://pypi.doubanio.com/simple


# 拷贝项目
COPY . /app/


# 让Cron服务在容器启动时运行
CMD cron && tail -f /var/log/cron.log
